package multithreading;

/**
 * join的使用
 * 实现t1->t2->t3的执行顺序
 */
public class JoinMethod {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println(Thread.currentThread().getName() + ":" + i);
            }
        }, "t1");
        Thread t2 = new Thread(() -> {
            try {
                t1.join();
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName() + ":" + i);
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }, "t2");
        Thread t3 = new Thread(() -> {
            try {
                t2.join();
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName() + ":" + i);
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        }, "t3");
        t1.start();
        t2.start();
        t3.start();

    }

}
